<?php

namespace App\Http\Controllers;

use App\Datatables;
use App\User;
use Illuminate\Http\Request;

/**
 * Class UserController
 * @package App\Http\Controllers
 */
class UserController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }


    /**
     * 用户列表
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
     */
    public function userList(Request $request)
    {
        if ($request->isMethod('post')) {
            return response()->json(Datatables::UserList());
        }

        return view('user.list');
    }


    /**
     * 解禁
     * @param $c_id
     * @return array
     */
    public function userBanon($c_id)
    {
        $user = User::where('c_id', $c_id)->exists();
        if (!$user) return ['status' => 2, 'message' => '无此用户'];
        if (!User::where('c_id', $c_id)->update([
            'ban_status' => User::BANSTATUS_ON
        ])) {
            return ['status' => 2, 'message' => '失败'];
        }
        return ['status' => 1, 'message' => '成功'];
    }

    /**
     * 禁言
     * @param $c_id
     * @return array
     */
    public function userBanoff($c_id, Request $request)
    {
        $user = User::where('c_id', $c_id)->exists();
        if (!$user) return ['status' => 2, 'message' => '无此用户'];
        return User::Ban($c_id, $request);
    }
}
